package com.nsl.my_youlai.mystar.enums.auxiliary;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.nsl.my_youlai.mystar.enums.NslEnumBaseI;
import com.nsl.my_youlai.mystar.enums.NslEnumTransformException;
import com.nsl.my_youlai.mystar.enums.NslEnumUploadStatus;


import java.io.IOException;
import java.util.Iterator;

public class UploadStatusEnumDeserializer extends StdDeserializer<NslEnumUploadStatus> {

    public UploadStatusEnumDeserializer() {
        this(null);

    }

    protected UploadStatusEnumDeserializer(Class<?> vc) {
        super(vc);
    }

    @Override
    public NslEnumUploadStatus deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {


        //System.out.println(jsonParser.getCodec());
        JsonNode node = jsonParser.getCodec().readTree(jsonParser);
        Iterator<String> fieldNameIt = node.fieldNames();
//        while ((fieldNameIt.hasNext())) {
//            System.out.println(fieldNameIt.next());
//        }
//        String label = node.get("label").asText();
//        System.out.println("label = " + label);
        Integer value = node.get("value").intValue();

        try {
            return NslEnumBaseI.getEnumByValue(value, NslEnumUploadStatus.class);
        } catch (NslEnumTransformException e) {
            throw new RuntimeException(e);
        }

//        System.out.println("label = "+node.get("label").asText());
//        System.out.println("value = "+node.get("value").asText());

//        return IBaseEnum.getEnumByValue(0,NslEnumBaseI.class);

    }
}
